home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 June / SGI Freeware 1998 June.iso / dist / fw_python.idb / usr / freeware / doc / python-1.2 / tkinter / packer-and-placer-together.py.z / packer-and-placer-together.py
Text File  |  1997-09-09  |  1KB  |  51 lines

  1. from Tkinter import *
  2.  
  3. # This is a program that tests the placer geom manager in conjunction with 
  4. # the packer. The background (green) is packed, while the widget inside is placed
  5.  
  6.  
  7. def do_motion(event):
  8.     app.button.place({'x' : event.x, 
  9.               'y' : event.y})
  10.  
  11. def dothis():
  12.     print 'calling me!'
  13.  
  14. def createWidgets(top):
  15.     # make a frame. Note that the widget is 200 x 200
  16.     # and the window containing is 400x400. We do this
  17.     # simply to show that this is possible. The rest of the
  18.     # area is inaccesssible.
  19.     f = Frame(top, {'width' : '200', 
  20.             'height' : '200',
  21.             'bg' : 'green'})
  22.  
  23.     # note that we use a different manager here. 
  24.     # This way, the top level frame widget resizes when the 
  25.     # application window does. 
  26.     f.pack({'fill' : 'both', 
  27.         'expand' : 1})
  28.  
  29.     # now make a button
  30.     f.button = Button(f, {'fg' : 'red', 
  31.               'text' : 'amazing', 
  32.               'command' : dothis})
  33.     
  34.     # and place it so that the nw corner is 
  35.     # 1/2 way along the top X edge of its' parent
  36.     f.button.place({'relx' : '0.5', 
  37.             'rely' : '0.0', 
  38.             'anchor' : 'nw'})
  39.     
  40.     # allow the user to move the button SUIT-style.
  41.     f.bind('<Control-Shift-Motion>', do_motion)
  42.  
  43.     return f
  44.  
  45. root = Tk()
  46. app = createWidgets(root)
  47. root.geometry("400x400")
  48. root.maxsize(1000, 1000)
  49. root.mainloop()
  50.  
  51.